﻿using Sustainalytics.ClientDW.DataAccessLayer;
using Sustainalytics.ClientDW.Entities;
using Sustainalytics.Utils;
using System;
using System.Collections.Generic;

namespace Sustainalytics.GCCS
{
    public class GCOverallCompanySummaryExtendedManager : IGCOverallCompanySummaryExtendedManager
    {
        private readonly IClientDWGlobalCompactRepository _gccRepo;


        public GCOverallCompanySummaryExtendedManager(IClientDWGlobalCompactRepository gccRepo)
        {
            this._gccRepo = gccRepo;
        }


        public int GetCount(GCOverallCompanySummaryExtendedFilters filters, List<int> universeIds, GCAssessment? overallAssessment)
        {
            string args = LogArgument.GetString(new { overallAssessment = overallAssessment });

            try
            {
                GCCEventSource.Log.GCOverallCompanySummaryExtended_GetCount(args);

                int count = _gccRepo.GetGCOverallCompanySummaryExtendedCount(filters, universeIds, overallAssessment);

                GCCEventSource.Log.GCOverallCompanySummaryExtended_GetCount_Success(args);

                return count;
            }
            catch (Exception ex)
            {
                GCCEventSource.Log.GCOverallCompanySummaryExtended_GetCount_Error(args, ex);
                throw;
            }
        }

        public List<GCOverallCompanySummaryExtended> GetList(
            GCOverallCompanySummaryExtendedFilters filters,
            List<int> universeIds, GCAssessment? overallAssessment, int? skip, int? take, string[] orderBy = null, bool orderByAsc = true)
        {
            string args = LogArgument.GetString(
                new 
                { 
                    overallAssessment = overallAssessment, 
                    skip = skip, 
                    take = take,
                    orderBy = orderBy,
                    orderByAsc = orderByAsc
                });

            try
            {
                GCCEventSource.Log.GCOverallCompanySummaryExtended_GetList(args);

                List<GCOverallCompanySummaryExtended> lst = _gccRepo.GetGCOverallCompanySummaryExtendedList(filters, universeIds, overallAssessment, skip, take, orderBy, orderByAsc);

                GCCEventSource.Log.GCOverallCompanySummaryExtended_GetList_Success(args);

                return lst;
            }
            catch (Exception ex)
            {
                GCCEventSource.Log.GCOverallCompanySummaryExtended_GetList_Error(args, ex);
                throw;
            }
        }
    }
}
